﻿using MediatR;
using Production_Get.API.Application.Commands.OrderShow;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.Warehousing;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Get.API.Application.Commands.Warehousingtes
{
    //入库反填
    public class StorageManHandler : IRequestHandler<StorageManCommend, Result>
    {
        private readonly IBaseRepositoryGet<StorageDto> StorageDto;

        public StorageManHandler(IBaseRepositoryGet<StorageDto> StorageDto)
        {
            this.StorageDto = StorageDto;
        }

        public async Task<Result> Handle(StorageManCommend request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Search };

            string sql = "SELECT * FROM Storage a INNER JOIN PurchasingType b on a.PurchasingTypeId=b.PurchasingTypeId INNER JOIN Purchasings c on a.PurchasinId=c.PurchasinId" +
                " INNER JOIN Warehouse d on a.WarehouseId = d.WarehouseId where StorageId=" + request.StorageId;
            var list = StorageDto.GetAll(sql, default).FirstOrDefault();
            if (list != null)
            {
                result.Code = (int)CommonErrorCodes.Success;
                result.Data = list;
                result.Msg = "反填成功";
            }

            return result;
        }
    }
}
